package org.deadline.model.config;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.deadline.model.baseapp.BaseEntity;
import org.deadline.model.baseapp.Organization;
import org.deadline.model.user.Person;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

@Entity
public class CustomFormElement extends BaseEntity  implements Serializable {

    @NotNull
    @Size(min = 3, max = 255)
    private String screenType;

    @NotNull
    @Size(min = 3, max = 100)
    private String controlType;

    @NotNull
    @Size(min = 3, max = 100)
    private String defaultconfigValues;

    @NotNull
    @Size(min = 3, max = 100)
    private String optionconfigValuess;

    @NotNull
    @Size(min = 3, max = 100)
    private String uiconfigKey;

    @NotNull
    @Size(min = 3, max = 100)
    private String uiLabel;

    @NotNull
    private Integer uiOrder;

    @NotNull
    private boolean displayed;

    @NotNull
    private boolean remember;

    @NotNull
    private boolean required;

    @NotNull
    @Size(min = 2, max = 1000)
    private String description;

    @NotNull
    private boolean enabled;

    @ManyToOne
    private Organization organization;

    @ManyToOne
    private Person owner;

	@Id
	@Column(name="id",unique=true,nullable=false)
	@SequenceGenerator(name="custom_form_element_seq_gen",sequenceName="custom_form_element_seq")
	@GeneratedValue(generator="custom_form_element_seq_gen",strategy=GenerationType.TABLE)
	@Generated(GenerationTime.INSERT)
	private Long id;

	
	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

	private static final long serialVersionUID = 1L;

	public String toJson() {
        return new JSONSerializer().exclude("*.class").deepSerialize(this);
    }

	public static CustomFormElement fromJsonToCustomFormElement(String json) {
        return new JSONDeserializer<CustomFormElement>().use(null, CustomFormElement.class).deserialize(json);
    }

	public static String toJsonArray(Collection<CustomFormElement> collection) {
        return new JSONSerializer().exclude("*.class").deepSerialize(collection);
    }

	public static Collection<CustomFormElement> fromJsonArrayToCustomFormElements(String json) {
        return new JSONDeserializer<List<CustomFormElement>>().use(null, ArrayList.class).use("values", CustomFormElement.class).deserialize(json);
    }

	public String getScreenType() {
        return this.screenType;
    }

	public void setScreenType(String screenType) {
        this.screenType = screenType;
    }

	public String getControlType() {
        return this.controlType;
    }

	public void setControlType(String controlType) {
        this.controlType = controlType;
    }

	public String getDefaultconfigValues() {
        return this.defaultconfigValues;
    }

	public void setDefaultconfigValues(String defaultconfigValues) {
        this.defaultconfigValues = defaultconfigValues;
    }

	public String getOptionconfigValuess() {
        return this.optionconfigValuess;
    }

	public void setOptionconfigValuess(String optionconfigValuess) {
        this.optionconfigValuess = optionconfigValuess;
    }

	public String getUiconfigKey() {
        return this.uiconfigKey;
    }

	public void setUiconfigKey(String uiconfigKey) {
        this.uiconfigKey = uiconfigKey;
    }

	public String getUiLabel() {
        return this.uiLabel;
    }

	public void setUiLabel(String uiLabel) {
        this.uiLabel = uiLabel;
    }

	public Integer getUiOrder() {
        return this.uiOrder;
    }

	public void setUiOrder(Integer uiOrder) {
        this.uiOrder = uiOrder;
    }

	public boolean isDisplayed() {
        return this.displayed;
    }

	public void setDisplayed(boolean displayed) {
        this.displayed = displayed;
    }

	public boolean isRemember() {
        return this.remember;
    }

	public void setRemember(boolean remember) {
        this.remember = remember;
    }

	public boolean isRequired() {
        return this.required;
    }

	public void setRequired(boolean required) {
        this.required = required;
    }

	public String getDescription() {
        return this.description;
    }

	public void setDescription(String description) {
        this.description = description;
    }

	public boolean isEnabled() {
        return this.enabled;
    }

	public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

	public Organization getOrganization() {
        return this.organization;
    }

	public void setOrganization(Organization organization) {
        this.organization = organization;
    }

	public Person getOwner() {
        return this.owner;
    }

	public void setOwner(Person owner) {
        this.owner = owner;
    }

	public Long getId() {
	    return this.id;
	}

	public void setId(Long id) {
	    this.id = id;
	}

	}
